package com.heima.article.feign;

import com.heima.article.service.ArticleService;
import com.heima.common.exception.CustomException;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleFeign {
    @Autowired
    private ArticleService articleService;


    @PostMapping("/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto){

        //参数效验
        if (StringUtils.isBlank(dto.getTitle()) || StringUtils.isBlank(dto.getContent())){
            throw  new CustomException(AppHttpCodeEnum.PARAM_INVALID);
        }
        //保存文章
        //1 携带id更新
        //2 没有携带id新增 保存到三张表中article config content
        Long articleId = articleService.saveArticle(dto);

        return ResponseResult.okResult(articleId);

    }
}
